
var currency = '-';
var exchange = 1.0;
var exchange_item = 1.0;

$(function() {
	Tip.emp('负责人');
	
	$("input[id^='date']:visible").datepicker(_date1_option);
	
	$('textarea').css("width", 400);
	
	var options = {
			editable: true,
		    enableAddRow: true,
		    enableCellNavigation: true,
		    asyncEditorLoading: false,
		    rowHeight: 30    
		};	
	
	var grid = new Slick.Grid($("#myGrid"), data, columns, options);
	
	grid.onAddNewRow.subscribe(function (e, args) {
		var item = {name:"", amount:"0.00", ok: true};
		// item.date = current_date();
		
	    $.extend(item, args.item);
	    data.push(item);
	    grid.invalidateRows([data.length - 1]);
	    grid.updateRowCount();
	    grid.render();
	});
	
	grid.onCellChange.subscribe(function(e, args) {
		
		item = args.item;
		currentCell = args.cell;
		currentRow = args.row;
    	
		// The data has changed - recalculate the totals.
	    // dataProvider.updateTotals();

	    // Rerender the totals row (last row).
	    // grid.invalidateRow(dataProvider.getLength() - 1);
		grid.updateRowCount();
	    grid.render();
	    // total();
	});
});

function _currency(s) {
	if (s == null || s == '-')　{		
		return false;
	}
	
	var body = { };
	body.currency = s;
	$.post('finance.php?do=Finance.ajax_exchange', body, function(s) {
		exchange = s;
		$('#rate').val(s);
		
		_update();
	});
}

function _update() {
	var a = $("#amount").val();
	var b = $("#currency").find("option:selected").text();
	
	a = a.replace(/,/g, '');

	Currency.upper(a, b, "#label_amount");
	
	_rmb();
} 

function _rmb() {
	var a = $("#amount").val();
	var b = $('#rate').val();
	
	a = a.replace(/,/g, '');
	b = b.replace(/,/g, '');
	
	var rmb = fxmul(a, b);
	
	$('#rmb').val(rmb);	
}